package com.hh.service.Impl;

import com.hh.dto.ResultDTO;
import com.hh.mapper.CoachGradeMapper;
import com.hh.model.TypeModel;
import com.hh.service.TypeService;
import com.hh.until.JSONCopy;
import com.hh.vo.TypeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CoachGradeServiceImpl implements TypeService {
    @Autowired
    private CoachGradeMapper coachGradeMapper;

    @Override
    public ResultDTO add(TypeVO typeVO) {
        TypeModel typeModel = JSONCopy.copy(typeVO, TypeModel.class);
        return ResultDTO.getDto(coachGradeMapper.add(typeModel), null);
    }

    @Override
    public ResultDTO delete(TypeVO typeVO) {
        TypeModel typeModel = JSONCopy.copy(typeVO, TypeModel.class);
        return ResultDTO.getDto(coachGradeMapper.delete(typeModel), null);
    }

    @Override
    public ResultDTO update(TypeVO typeVO) {
        TypeModel typeModel = JSONCopy.copy(typeVO, TypeModel.class);
        return ResultDTO.getDto(coachGradeMapper.update(typeModel), null);
    }

    @Override
    public ResultDTO findAll(TypeVO typeVO) {
        TypeModel typeModel = JSONCopy.copy(typeVO, TypeModel.class);
        if (typeModel.getPage() != null) {
            typeModel.setPage((typeModel.getPage()-1)*typeModel.getLimit());
        }
        List<TypeModel> typeModelList = coachGradeMapper.findAll(typeModel);
        return ResultDTO.getDto(coachGradeMapper.count(typeModel),typeModelList);
    }

    @Override
    public ResultDTO findById(TypeVO typeVO) {
        TypeModel typeModel = JSONCopy.copy(typeVO, TypeModel.class);
        return ResultDTO.getDto(0,coachGradeMapper.findById(typeModel));
    }

    @Override
    public ResultDTO count(TypeVO typeVO) {
        TypeModel typeModel = JSONCopy.copy(typeVO, TypeModel.class);
        return ResultDTO.getDto(coachGradeMapper.count(typeModel),null);
    }
}
